﻿using System.Windows.Forms;

public static class TableTools {
	/// <summary>
	/// Получить колонки для таблицы (редактора) книг
	/// </summary>
	public static DataGridViewColumn[] GetColsForEditorBooks() {
		var columnSelect = new DataGridViewCheckBoxColumn {
			Name = "ColumnSelect",
			HeaderText = @"Select",
			Resizable = DataGridViewTriState.True,
			Width = 50,
			FillWeight = 50F,
			SortMode = DataGridViewColumnSortMode.Automatic,
			ReadOnly = false
		};

		var columnName = new DataGridViewTextBoxColumn {
			Name = "ColumnName",
			HeaderText = @"Name",
			Resizable = DataGridViewTriState.True,
			Width = 200,
			ReadOnly = true
		};

		var columnExtension = new DataGridViewTextBoxColumn {
			Name = "ColumnExtension",
			HeaderText = @"Extension",
			Resizable = DataGridViewTriState.True,
			Width = 60,
			ReadOnly = true
		};

		var columnLength = new DataGridViewTextBoxColumn {
			Name = "ColumnLength",
			HeaderText = @"Length",
			Resizable = DataGridViewTriState.True,
			Width = 100,
			ReadOnly = true
		};

		var columnPath = new DataGridViewTextBoxColumn {
			Name = "ColumnPath",
			HeaderText = @"RootPath",
			Resizable = DataGridViewTriState.True,
			Width = 200,
			ReadOnly = true
		};

		return new DataGridViewColumn[] { columnSelect, columnName, columnExtension, columnLength, columnPath };
	}

	/// <summary>
	/// Создать строку для таблицы (редактора) книг
	/// </summary>
	public static DataGridViewRow CreateRowForBooks(DataGridView dataGridView, params object[] values) {
		var row = new DataGridViewRow();
		row.CreateCells(dataGridView, values);
		return row;
	}

	/// <summary>
	/// Удалить выбранные строки из таблицы книг
	/// </summary>
	public static DataGridViewRowCollection RemoveSelectedRowBooks(DataGridViewRowCollection collection) {
		for(var index = 0; index < collection.Count; index++) {
			if(collection[index].Cells["ColumnSelect"].Value == true.ToString()) {
				collection.Remove(collection[index]);
				index--;
			}
		}
		return collection;
	}

	/// <summary>
	/// Получить колонки для таблицы (основной) книг
	/// </summary>
	public static DataGridViewColumn[] GetColumnsForBooks() {
		var columnSelect = new DataGridViewCheckBoxColumn {
			Name = "ColumnSelect",
			HeaderText = @"Select",
			Resizable = DataGridViewTriState.True,
			Width = 50,
			FillWeight = 50F,
			SortMode = DataGridViewColumnSortMode.Automatic,
			ReadOnly = false
		};

		var columnName = new DataGridViewTextBoxColumn {
			Name = "ColumnName",
			HeaderText = @"Name",
			Resizable = DataGridViewTriState.True,
			Width = 200,
			ReadOnly = true
		};

		var columnTitle = new DataGridViewTextBoxColumn {
			Name = "ColumnTitle",
			HeaderText = @"Title",
			Resizable = DataGridViewTriState.True,
			Width = 150,
			ReadOnly = true
		};

		var columnAuthors = new DataGridViewTextBoxColumn {
			Name = "ColumnAuthors",
			HeaderText = @"Authors",
			Resizable = DataGridViewTriState.True,
			Width = 60,
			ReadOnly = true
		};

		var columnYear = new DataGridViewTextBoxColumn {
			Name = "ColumnYear",
			HeaderText = @"Year",
			Resizable = DataGridViewTriState.True,
			Width = 50,
			ReadOnly = true
		};

		var columnEdition = new DataGridViewTextBoxColumn {
			Name = "ColumnEdition",
			HeaderText = @"Edition",
			Resizable = DataGridViewTriState.True,
			Width = 50,
			ReadOnly = true
		};

		var columnExtension = new DataGridViewTextBoxColumn {
			Name = "ColumnExtension",
			HeaderText = @"Extension",
			Resizable = DataGridViewTriState.True,
			Width = 60,
			ReadOnly = true
		};

		var columnLength = new DataGridViewTextBoxColumn {
			Name = "ColumnLength",
			HeaderText = @"Length",
			Resizable = DataGridViewTriState.True,
			Width = 100,
			ReadOnly = true
		};

		var columnLaunch = new DataGridViewButtonColumn() {
			Name = "ColumnLaunch",
			HeaderText = @"Launch",
			Text = @"Start",
			Resizable = DataGridViewTriState.True,
			Width = 50,
			ReadOnly = true,
			UseColumnTextForButtonValue = true
		};

		var columnPath = new DataGridViewTextBoxColumn {
			Name = "ColumnPath",
			HeaderText = @"RootPath",
			Resizable = DataGridViewTriState.True,
			Width = 100,
			ReadOnly = true
		};

		return new DataGridViewColumn[] {columnSelect, columnName, columnTitle, columnAuthors, columnYear, columnEdition, columnExtension, columnLength, columnLaunch, columnPath };
	}
}
